PCA Index Interactive Visualization Examples

PCA Index Interactive Visualization Examples#

import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR

import warnings
warnings.filterwarnings('ignore')
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot(color="red")
<Axes: xlabel='DATE'>
../_images/46636c8bba93e3795335b4b4315cc8197ebcddff4804a1917d9bcc7f2673fd30.png
# Simple version
fig = px.line(pc1)
fig.show()
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
../_images/212be10ba6d3f00a51f40f2d930771e9f0315ce1695af62de39295fa152803b1.png
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
pca_index.plot_unnormalized_series(df)
pca_index.plot_normalized_series(dfn)